@extends('home.layout.base')
@section('title', '站内消息')
@section('pluginstyle')
<script src="{{ asset('/dist/home/js/1102.js') }}"></script>
<link rel="stylesheet" href="{{ asset('/dist/home/css/qikoo_user.css') }}">
<script>var _isindex = 0;</script>
<style type="text/css">
    .readed{color:#ddd}
</style>
@endsection
@section('content')
<div class="user-body">
    <div class="user-container">
        <div class="user-crumbs m-b-10">
            <a href="{{ url('/user') }}">首页</a> > 站内消息
        </div>
        <div class="clearfix_new">
            @include('home.user.menu')
            <div class="user-main">
                <div class="order-main clearfix_new">
                    <h1 style="border:0">站内消息 </h1>
                    <div class="mod-user-list">
                        <ul id="ul_order_type" class="order_type" style="margin-bottom:20px;padding:0 0 0 10px">
                            <li data-order_type="-1" _class="cur" data-status="-1">
                                <a class="order_type_title" href="{{ url('/user/message/readall') }}">全设已读</a>
                            </li>
                            <li data-order_type="0" _class="disable" data-status="0">
                                <a class="order_type_title" href="{{ url('/user/message/deleteall') }}">全部删除</a>
                            </li>
                        </ul>
                        <table style="" width="100%" border="0" cellspacing="0" cellpadding="0">
                            <thead>
                                <tr class="list-title">
                                    <th class="list-col2">
                                        消息标题
                                    </th>
                                    <th class="list-col1">
                                        消息内容
                                    </th>
                                    <th class="list-col4">
                                        发送时间
                                    </th>
                                    <th class="list-col3">
                                        消息类型
                                    </th>
                                    <th class="list-col4">
                                        操作
                                    </th>
                            </thead>
                            <tfoot>
                                <tr>
                                    <td colspan="5">{!! $messageList->render() !!}</td>
                                </tr>
                            </tfoot>
                            <tbody>
                                @if($messageList->all())
                                @foreach($messageList as $msg)
                                {{-- 如果已阅读，则当前行加中横线 --}}
                                @if($msg->is_read == 1)
                                <tr class="readed">
                                @else
                                <tr>
                                @endif
                                    <td>{{ $msg->msgInfo->msg_title }}</td>
                                    <td>{{ str_limit($msg->msgInfo->msg_content, 50) }}</td>
                                    <td>{{ $msg->msgInfo->msg_time }}</td>
                                    <td>
                                        {{ $msg->msgInfo->msg_type == 0 ? '系统通知' : '个人消息' }}
                                    </td>
                                    <td>
                                        <a href="{{ url('/user/message/read', [$msg->msg_id]) }}" class="msg-read">
                                            {{ $msg->is_read == 1 ? '已读' : '未读' }}
                                        </a>
                                        <a href="{{ url('/user/message/delete', [$msg->id]) }}" class="msg-del">删除</a>
                                    </td>
                                </tr>
                                @endforeach
                                @else
                                <tr>
                                    <td style="line-height:170px;text-align:center" colspan="4">
                                        暂无消息
                                    </td>
                                </tr>
                                @endif
                            </tbody>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div id="wuliu" class="wuliu_wrap" style="left:300px;top:200px;z-index:100;width:600px;">
                    <div class="dialog_content">
                        <p style="border-bottom:1px solid #ececec;color:#666;font-weight:700;height:40px;line-height:40px;width:550px">
                            <span style="display:inline-block;margin-left:35px" class="msg-title"></span>
                            <button id="msg-close" style="float:right">&timesb;</button>
                        </p>
                        <p class="contenttext msg-content">
                            
                        </p>
                        <ul class="order_info_ul">
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
@section('pluginscript')
<script type="text/javascript">
$(function(){
    // ajax进行查看消息
    $('.msg-read').click(function(){
        url = $(this).attr('href');
        var that = $(this);
        $.get(url, '', function(msg){
            if(msg.status == 1){
                $('.wuliu_wrap').show();
                $('.msg-title').text(msg.info.msg_title);
                $('.msg-content').text(msg.info.msg_content);
                that.text('已读');
                that.parents('tr').addClass('readed');
            } else {
                alert(msg.info);
            }
        });
        return false;
    });
    // 关闭消息面板
    $('#msg-close').click(function(){
        $('.wuliu_wrap').hide();
    });
    
    // ajax删除消息
    $('.msg-del').click(function(){
        url = $(this).attr('href');
        var that = $(this);
        $.get(url, '', function(msg){
            if(msg.status == 1){
                that.parents('tr').remove();
            } else {
                alert(msg.info);
            }
        });
        return false;
    });
});
</script>
@endsection